package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.tool.GlideUtils;
import com.runen.infinitemovement.widget.imageview.RoundedCornersImage;
import com.runen.rxnetlibrary.utils.LogUtil;

import java.util.List;

public class AddPictureAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private Context context;

    public OnDeleteClick getOnDeleteClick() {
        return onDeleteClick;
    }

    public void setOnDeleteClick(OnDeleteClick onDeleteClick) {
        this.onDeleteClick = onDeleteClick;
    }

    private OnDeleteClick onDeleteClick;

    public AddPictureAdapter(Context context) {
        super(R.layout.item_add_picture);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, String item) {
        RelativeLayout rl_picture = helper.getView(R.id.rl_picture);
        RoundedCornersImage rci_img = helper.getView(R.id.rci_img);
        ImageView iv_add_picture = helper.getView(R.id.iv_add_picture);
        ImageView iv_delete = helper.getView(R.id.iv_delete);
        if (item.equals("nullUrl")) {
            rl_picture.setVisibility(View.GONE);
            iv_add_picture.setVisibility(View.VISIBLE);
        } else {
            GlideUtils.loadImage(context, item, rci_img);
            rl_picture.setVisibility(View.VISIBLE);
            iv_add_picture.setVisibility(View.GONE);
        }
        iv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDeleteClick != null) {
                    onDeleteClick.onDelete(item);
                }
            }
        });
    }

    public interface OnDeleteClick {
        void onDelete(String item);
    }
}
